package com.kust.smarthome.web.controller;


import com.kust.smarthome.web.model.OrderForm;
import com.kust.smarthome.web.service.AlipayService;
import com.kust.smarthome.web.service.IOrderFormService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Author Sakura
 * @Date 9/9/2019
 **/
@Controller
@RequestMapping("/alipay")
public class AlipayController {

    @Resource
    private IOrderFormService orderFormService;

    @Autowired
    private AlipayService alipayService;

    @GetMapping("/create")
    @ResponseBody
    public String create(@RequestParam("orderId") String orderId) {
        //发起支付
        OrderForm orderForm = orderFormService.getById(orderId);
        String payUrl = alipayService.create(orderForm);
        return payUrl;
    }

    /**
     * 支付宝异步通知
     */
    @PostMapping("/notify")
    public void notify(HttpServletRequest request) {
        System.out.println("来了");
        alipayService.notify(request);
    }
}